18. Exercise: Make an AsyncTask
Make an AsyncTask
Optional Exercise Code
Exercise: T08.02-Exercise-AddAsyncTaskToRetrieveCursor
If you’d like the skip this, you can simply check out the following branch and review the diff TODO at the bottom.
If you’d like to do it yourself, the end goal is to make an AsyncTask that loads the data on a background thread in a Cursor object. It then updates a variable called mData in the MainActivity to store the returned Cursor.
Steps to get the data from the Content Provider and save it into an instance variable
- Create an
AsyncTaskwith the following generic types<Void, Void, Cursor> - In the
doInBackgroundmethod, write the code to access the DroidTermsExample provider and return theCursorobject. - Create an instance variable
Cursor mData. - In the
onPostExecutemethod, store theCursorobject inmData. - Create and execute the
AsyncTaskinonCreate.
Solution: [T08.02-Solution-AddAsyncTaskToRetrieveCursor][Diff]